﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using YiSha.Business.Business;
using YiSha.Entity.Business;
using YiSha.Model.Param.Business;
using YiSha.Util;
using YiSha.Util.Model;

namespace YiSha.Admin.Web.Controllers
{
    public class PrescriptionController : BaseController
    {

        private PrescriptionBLL prescriptionBLL = new PrescriptionBLL();

        #region 视图功能

        [AuthorizeFilter("business:prescription:view")]
        public IActionResult PrescriptionIndex()
        {
            return View();
        }


        public IActionResult PrescriptionForm()
        {
            return View();
        }



        public IActionResult PrescriptionEndForm()
        {
            return View();
        }

        #endregion

        #region 获取数据
        [HttpGet]
        [AuthorizeFilter("business:prescription:search,business:prescription:view")]
        public async Task<IActionResult> GetListJson(PrescriptionListParam param)
        {
            TData<List<PrescriptionEntity>> obj = await prescriptionBLL.GetList(param);
            return Json(obj);
        }

        [HttpGet]
        [AuthorizeFilter("business:prescription:search,business:prescription:view")]
        public async Task<IActionResult> GetPageListJson(PrescriptionListParam param, Pagination pagination)
        {
            TData<List<PrescriptionEntity>> obj = await prescriptionBLL.GetPageList(param, pagination);
            return Json(obj);
        }

        [HttpGet]
        public async Task<IActionResult> GetFormJson(long id)
        {
            TData<PrescriptionEntity> obj = await prescriptionBLL.GetEntity(id);
            return Json(obj);
        }

     
        #endregion

        #region 提交数据
        [HttpPost]
        [AuthorizeFilter("business:prescription:add,business:prescription:edit")]
        public async Task<IActionResult> SaveFormJson(PrescriptionEntity entity)
        {
            TData<string> obj = await prescriptionBLL.SaveForm(entity);
            return Json(obj);
        }


        /// <summary>
        /// 完成治疗
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> SaveEndJson(PrescriptionEntity entity)
        {
            TData<string> obj = await prescriptionBLL.SaveEnd(entity);
            return Json(obj);
        }



        [HttpPost]
        [AuthorizeFilter("business:prescription:delete")]
        public async Task<IActionResult> DeleteFormJson(string ids)
        {
            TData obj = await prescriptionBLL.DeleteForm(ids);
            return Json(obj);
        }
        #endregion

    }
}
